<template>
  <div class="my">
    <div class="top">
      <div class="top-info" @click="goInfo">
        <div class="left">
          <div class="left-title">{{ userInfo.nickname }}</div>
          <div class="left-txt">{{ userInfo.intro }}</div>
        </div>
        <img
          v-if="userInfo.avatar"
          :src="baseUrl + userInfo.avatar"
          class="right"
          alt=""
        />
        <img v-else src="@/assets/logo.png" class="right" alt="" />
      </div>
      <ul class="top-num">
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">累计答题</div>
        </li>
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">收藏题目</div>
        </li>
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">我的错题</div>
        </li>
        <li class="top-num-item">
          <div class="num">298</div>
          <div class="txt">正确率</div>
        </li>
      </ul>
      <div class="position">
        <!-- 单元格
        van-cell
            title:左边文本
            value:右边文本
            is-link:剪头
            center:上下居中
            slot="icon/title/default/right-icon"
         -->
        <!-- <van-cell is-link center class="cell">
          <template #icon>
            <i class="iconfont">&#xe64d;</i>
          </template>
          <template #title>
            <div class="cell-title">
              我的岗位
            </div>
          </template>
          <template #default>
            <div class="cell-value">
              产品经理
            </div>
          </template>
        </van-cell> -->
        <!-- 
          父传子属性
             传: 子组件标签上定义一个属性  属性名=值
             收:子组件内定义一个props:["属性名"]
         -->
        <myCell
          class="cell"
          icon="&#xe64d;"
          title="我的岗位"
          :value="userInfo.position"
          @click.native="$router.push('/home/editInfo?type=position')"
        >
          <!-- @click.native="goEdit('position')" 
          this.$router.push('/home/editInfo?type=' + str)-->
        </myCell>
      </div>
    </div>

    <div class="content">
      <div class="middle">
        <h3 class="middle-title">面试数据</h3>
        <ul class="middle-num">
          <li class="middle-num-item">
            <div class="item-1">昨日阅读<span class="color">+300</span></div>
            <div class="item-2">
              {{ userInfo.shareData ? userInfo.shareData.read.total : 0 }}
            </div>
            <div class="item-3">阅读总数</div>
          </li>
          <li class="middle-num-item">
            <div class="item-1">昨日阅读<span class="color">+300</span></div>
            <div class="item-2">17</div>
            <div class="item-3">阅读总数</div>
          </li>
          <li class="middle-num-item">
            <div class="item-1">昨日阅读<span class="color">+300</span></div>
            <div class="item-2">17</div>
            <div class="item-3">阅读总数</div>
          </li>
        </ul>
      </div>
      <div class="bottom">
        <myCell
          class="cell"
          icon="&#xe655;"
          title="我的面经分享"
          value="21"
        ></myCell>
        <myCell
          class="cell"
          icon="&#xe656;"
          title="我的消息"
          value="98"
        ></myCell>
        <myCell
          class="cell"
          icon="&#xe654;"
          title="收藏的题库"
          value="32"
        ></myCell>
        <myCell
          class="cell"
          icon="&#xe648;"
          title="收藏的企业"
          value="32"
        ></myCell>
        <myCell
          class="cell"
          icon="&#xe64f;"
          title="我的错题"
          value="123"
        ></myCell>
        <myCell
          class="cell"
          icon="&#xe649;"
          title="收藏的面试经验"
          value="166"
        ></myCell>
      </div>
    </div>
  </div>
</template>

<script>
// 1:导入  2:注册  3:使用
import myCell from './myCell'
// 导入mapState
import { mapState } from 'vuex'
export default {
  components: {
    myCell
  },
  data () {
    return {
      baseUrl: process.env.VUE_APP_URL
    }
  },
  mounted () {
    // window.console.log('mapState:', mapState(['userInfo', 'isLogin']).userInfo)
  },
  methods: {
    goInfo () {
      this.$router.push('/home/myInfo')
    }
    // 修改岗位
    /*  goEdit (str) {
      this.$router.push('/home/editInfo?type=' + str)
    } */
  },
  computed: {
    // 使用场景:依赖一个或者多个值产生一个新的值
    // ...{a(){},b(){}}   a(){},b(){}
    /*
    ...{
    userInfo () {
      return this.$store.state.userInfo
    },
    isLogin () {
      return this.$store.state.userInfo
    }
    }
    */
    //  ...mapState(["希望取出store内的state的属性名"]
    ...mapState(['userInfo', 'isLogin'])
    // userInfo () {
    //   return this.$store.state.userInfo
    // },
    // isLogin () {
    //   return this.$store.state.userInfo
    // }
  }
}
</script>

<style lang="less">
.my {
  .top {
    position: relative;
    background: linear-gradient(45deg, #ce0031, #b8002c);
    padding: 31px @p15 55px;
    .top-info {
      // 使用弹性盒子
      display: flex;
      // 水平处理 内部子集最边上对齐 其他子项平均分
      justify-content: space-between;
      // 上下居中
      align-items: center;
      .left {
        .left-title {
          font-size: 21px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #ffffff;
          line-height: 30px;
          letter-spacing: 0px;
        }
        .left-txt {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: left;
          color: #ffffff;
          line-height: 33px;
          letter-spacing: 0px;
        }
      }
      .right {
        width: 50px;
        height: 50px;
        border: 6px solid rgba(255, 255, 255, 0.38);
        border-radius: 50%;
      }
    }
    .top-num {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .top-num-item {
        text-align: center;
        margin-top: 31px;
        .num {
          font-size: 21px;
          font-family: DINAlternate, DINAlternate-Bold;
          font-weight: 700;
          text-align: center;
          color: #ffffff;
          line-height: 24px;
          letter-spacing: 0px;
        }
        .txt {
          opacity: 0.7;
          font-size: 12px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          text-align: center;
          color: #ffffff;
          line-height: 16px;
          letter-spacing: 0px;
        }
      }
    }
    .position {
      position: absolute;
      left: 0;
      bottom: -16px;
      width: 100%;
      padding: 0 @p15;
      .cell {
        border-radius: 8px;
      }
    }
  }
  .content {
    background-color: #f7f4f5;
    padding: 26px @p15;
    .middle {
      padding: 19px 15px;
      background-color: #fff;
      .middle-title {
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        text-align: left;
        color: #181a39;
        line-height: 20px;
        letter-spacing: 0px;
      }
      .middle-num {
        display: flex;
        justify-content: space-around;
        text-align: center;
        padding-top: 17px;
        .middle-num-item {
          .item-1 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #b4b4bd;
            line-height: 14px;
            letter-spacing: 0px;
            .color {
              color: #00b8d4;
            }
          }
          .item-2 {
            font-size: 12px;
            font-family: DINAlternate, DINAlternate-Bold;
            font-weight: 700;
            text-align: center;
            color: #181a39;
            line-height: 24px;
            letter-spacing: 0px;
            padding: 10px 0;
          }
          .item-3 {
            font-size: 12px;
            font-family: PingFangSC, PingFangSC-Regular;
            font-weight: 400;
            text-align: center;
            color: #545671;
            line-height: 16px;
            letter-spacing: 0px;
          }
        }
      }
    }
    .bottom {
      margin-top: 10px;
      .cell:nth-child(1) {
        border-top-left-radius: 8px;
        border-top-right-radius: 8px;
      }
      .cell:nth-child(6) {
        border-bottom-left-radius: 8px;
        border-bottom-left-radius: 8px;
      }
      //  手动调整 margin-bottom:60px
    }
  }
}
</style>
